/**
 * @author ztl
 * @date 2016年10月21日上午9:18:29
 */
package com.zhihuishu.micro.course.log;

import com.zhihuishu.toolkit.log.LoggerTemplate;
import com.zhihuishu.toolkit.log.MDCInfoBuilder;

/**
 * @description 封装日志API：LoggerTemplate
 * @author ztl 2016年10月21日
 */
public class LoggerTemplateUtil {

   

    public static final LoggerTemplate logger=LoggerTemplate.getInstance(LoggerTemplate.class);
    public static void saveLogger(String message, Long userId, LoggerCollectionEnum loggerCollectionEnum) {
        try {
            StackTraceElement[] tmpElements = Thread.currentThread().getStackTrace();
            MDCInfoBuilder builder=MDCInfoBuilder.create();
            builder.setTableName("courseService", loggerCollectionEnum.getTableName())
            .setMethodName( tmpElements[2].getMethodName())
            .setModuleName(tmpElements[2].getClassName())
            .put("userId", userId==null?"0":userId.toString());
            logger.info(builder.build(), "{}", message);
           
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void saveLogger(String message, Long userId, LoggerCollectionEnum loggerCollectionEnum,
            Long courseId) {
        try {
            StackTraceElement[] tmpElements = Thread.currentThread().getStackTrace();
            MDCInfoBuilder builder=MDCInfoBuilder.create();
            builder.setTableName("courseService", loggerCollectionEnum.getTableName())
            .setMethodName( tmpElements[2].getMethodName())
            .setModuleName(tmpElements[2].getClassName())
            .put("userId", userId==null?"0":userId.toString())
            .put("courseId", courseId==null?"0":courseId.toString());
            logger.info(builder.build(), "{}", message);
           
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
